<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<div class="bjui-pageHeader" style="background-color:#fefefe; border-bottom:none;">
    <form data-toggle="ajaxsearch"
          data-options="{searchDatagrid:$.CurrentNavtab.find('#allpayment_table')}">
        <fieldset>
            <legend style="font-weight:normal;">条件搜索：</legend>
            <div style="margin:0; padding:1px 15px 15px;">
                <label class="row-label">用户名：</label>
                <input type="text" name="userName" class="form-control" size="15" title="用户名">

                <label class="row-label">&nbsp;流水号：</label>
                <input type="text" name="orderNo" class="form-control" size="15" title="流水号">

                <label class="row-label">&nbsp;交易类型：</label>
                <select data-toggle="selectpicker" name="type" data-width="150">
                    <option value="" selected>全部</option>
                    <c:forEach items="${applicationScope.flowStatusMap}" var="flowStatus">
                        <option value="${flowStatus.key}">${flowStatus.value}</option>
                    </c:forEach>
                </select>

                <label class="row-label">&nbsp;交易时间：</label>
                <input type="text" name="fromTo.from" data-toggle="datepicker" data-nobtn="true" size="11">
                <label class="row-label">-</label>
                <input type="text" name="fromTo.to" data-toggle="datepicker" data-nobtn="true" size="11">
                <label class="row-label"></label>
                <div class="btn-group">
                    <button type="submit" class="btn-green" data-icon="search">搜索</button>
                    <button type="reset" class="btn-orange" data-icon="times">重置</button>
                </div>
            </div>
        </fieldset>
    </form>
</div>
<div class="bjui-pageContent">
    <table id="allpayment_table" class="table table-bordered">
    </table>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/capital/capital.js"></script>
<script type="text/javascript">
    var allpayment_table;
    $(function () {
        allpayment_table = $("#allpayment_table").datagrid({
            height: '100%',
            width: '100%',
            fullGrid : true,
            showToolbar: true,
            filterThead: false,
            delPK: 'id',
            dataUrl: '/admin/capital/flow?_=' + new Date().getTime(),
            local: "remote",
            inlineEditMult: false,
            delConfirm: true,
            saveAll: false,
            showTfoot : true,
            addLocation: 'last',
            toolbarItem: 'refresh,',
            postData : {total : "allpayment"},
            toolbarCustom: function () {
                return '<button type="button" class="btn btn-green" onclick="allPaymentExport();" data-icon="sign-out"><i class="fa fa-sign-out"></i> 导出</button>';
            },
            columns: [{
                render: allPaymentShowUser,
                label: '发起者',
                align: 'center'
            }, {
                name: 'terminal',
                label: '终端',
                align: 'center'
            }, {
                name: 'type',
                label: '交易类型',
                align: 'center',
                items: flowType
            }, {
                name: 'amount',
                label: '金额',
                align: 'center',
                total: 'allpayment'
            }, {
                name: 'date',
                label: '交易时间',
                align: 'center',
                width: 250,
                pattern: 'yyyy-MM-dd HH:mm:ss',
                render: function (value) {
                    return value ? (value.length > 10 ? value.substr(0, 19): value) : value
                }
            }, {
                render: allPaymentShowInUser,
                label: '接受者',
                align: 'center'
            }, {
                name: 'remark',
                label: '备注',
                align: 'center'
            }, {
                name: 'status',
                label: '交易状态',
                align: 'center',
                items: flowStatus
            }, {
                name: 'orderNo',
                label: '流水号',
                align: 'center',
                width: 320
            }],
            paging: {pageSize: 20, pageIndex: 1},
            linenumberAll: true
        });

        function allPaymentShowUser(value, data) {
            return '<a href="javascript:;" onclick="allPaymentOpenDialog(\'' + data.userId + "','" + data.userName + '\')">' + data.userName + '</a>';
        }

        function allPaymentShowInUser(value, data) {
            return '<a href="javascript:;" onclick="allPaymentOpenDialog(\'' + data.inUserId + "','" + data.inUserName + '\')">' + data.inUserName + '</a>';
        }

    });
    function allPaymentOpenDialog(id, userName) {
        BJUI.dialog({
            id: 'userInfo_' + id,
            url: '/admin/user/userInfo?id=' + id,
            title: '' + userName + '用户信息',
            width: 1200,
            height: 1200 * 0.618
        });
    }

    function allPaymentExport() {
        var dates = $(allpayment_table).data('selectedDatas');
        if (dates && dates.length !== 0) {
            var ids = [];
            dates.forEach(function (e) {
                ids.push(e.id);
            });
            BJUI.ajax('ajaxdownload', {
                url: '/admin/capital/exportFlow',
                data: {ids: ids.join(",")}
            });
        } else
            BJUI.alertmsg('info', BJUI.getRegional('datagrid.selectMsg'))
    }
</script>